//Bf2 Rank Mod menu File
//Contains all the menu checking functions.


#if defined bf2_menu_included
  #endinput
#endif
#define bf2_menu_included

public Bf2menu(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE
    
	new menu = menu_create("\rBF2: Wybierz Menu:", "menu_handler")
 
	menu_additem(menu, "\wPomoc", "0", 0)
	menu_additem(menu, "\wStatystyki", "1", 0)
	menu_additem(menu, "\wAdministracja", "2", ADMIN_LEVEL)
	menu_additem(menu, "\wReset Statystyk", "3", 0)

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

	menuselection[id]=MENU_MAIN

	menu_display(id, menu, 0)

	return PLUGIN_CONTINUE 
}

public helpmenu(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE
    
	new menu = menu_create("\rBF2: Pomoc:", "menu_handler")
 
	menu_additem(menu, "\wPomoc", "0", 0)
	menu_additem(menu, "\wOdznaki 1", "1", 0)
	menu_additem(menu, "\wOdznaki 2", "2", 0)
	menu_additem(menu, "\wOdznaki 3", "3", 0)
	menu_additem(menu, "\wRanking", "4", 0)

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

	menuselection[id]=MENU_HELP

	menu_display(id, menu, 0)

	return PLUGIN_CONTINUE
}

public playerlist(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE
    
	new menu = menu_create("\rBF2: Wybierz Gracza:", "menu_handler")
 
	new players[32],num
	get_players(players,num,"h")
	new name[30]
	new player
	new tempstring[32]
	new idarray[3]
	
	for (new i=0; i<num; i++)
	{
		player=players[i]
		get_user_name(player,name,29)
		formatex(tempstring,49,"\w%s",name)
		formatex(idarray,2,"%i",player)
		menu_additem(menu, tempstring, idarray, 0)
	}

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

	menuselection[id]=MENU_PLAYER

	menu_display(id, menu, 0)

	return PLUGIN_CONTINUE
}

public statsmenu(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE
    
	new menu = menu_create("\rBF2: Statystyki:", "menu_handler")
 
	menu_additem(menu, "\wPokaz Liste Graczy", "0", 0)
	menu_additem(menu, "\wPokaz Twoje Odznaki", "1", 0)
	menu_additem(menu, "\wPokaz Twoje Statystyki", "2", 0)
	menu_additem(menu, "\wPokaz Statystyki Serwera", "3", 0)

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

	menuselection[id]=MENU_STATS

	menu_display(id, menu, 0)

	return PLUGIN_CONTINUE  
}

public confirmmenu(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE
    
	new menu = menu_create("\rJestes pewien?:", "menu_handler")
 
	menu_additem(menu, "\wReset Statystyk", "0", 0)

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

	menuselection[id]=MENU_CONFIRM

	menu_display(id, menu, 0)
	
	return PLUGIN_CONTINUE 
}

public confirmmenuadmin(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE
    
	new menu = menu_create("\rJestes Pewnien?:", "menu_handler")
 
	menu_additem(menu, "\wReset Statystyk", "0", ADMIN_RESET)

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

	menuselection[id]=MENU_CONFIRMADMIN

	menu_display(id, menu, 0)

	return PLUGIN_CONTINUE
}

public adminmenu(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE
	
	new menu = menu_create("\rBF2: Administracja:", "menu_handler")
 
	menu_additem(menu, "\wDaj Odznake Graczowi", "0", ADMIN_LEVEL)
	menu_additem(menu, "\wDaj Fragi Graczowi", "1", ADMIN_LEVEL)
	menu_additem(menu, "\wReset Statystyk Serwera", "2", ADMIN_RESET)

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)

	menuselection[id]=MENU_ADMIN

	menu_display(id, menu, 0)

	return PLUGIN_CONTINUE 
}

public badgemenu(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE

  	new menu = menu_create("\rBF2: Wybierz Odznaczenie:", "menu_handler")
 
	menu_additem(menu, "\wWalka Nozem", "0", ADMIN_LEVEL)
	menu_additem(menu, "\wWalka Pistoletem", "1", ADMIN_LEVEL)
	menu_additem(menu, "\wWalka Bronia Szturmowa", "2", ADMIN_LEVEL)
	menu_additem(menu, "\wWalka Bronia Snajperska", "3", ADMIN_LEVEL)
	menu_additem(menu, "\wWalka Bronia Wsparcia", "4", ADMIN_LEVEL)
	menu_additem(menu, "\wObeznanie z Materialami Wybuchowymi", "5", ADMIN_LEVEL)
	menu_additem(menu, "\wWalka Shotgunem", "6", ADMIN_LEVEL)
	menu_additem(menu, "\wWalka SMG", "7", ADMIN_LEVEL)
  
	menu_setprop(menu, MPROP_PERPAGE, 0)
	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  
	menuselection[id]=MENU_BADGE

	menu_display(id, menu, 0)

	return PLUGIN_CONTINUE
}

public badgelevelmenu(id)
{
	if (!get_pcvar_num(g_bf2_active))
		return PLUGIN_CONTINUE

   	new menu = menu_create("\rBF2: Wybierz Poziom:", "menu_handler")
 
	menu_additem(menu, "\wZaden", "0", ADMIN_LEVEL)
	menu_additem(menu, "\wPodstawowy", "1", ADMIN_LEVEL)
	menu_additem(menu, "\wWeteran", "2", ADMIN_LEVEL)
	menu_additem(menu, "\wExpert", "3", ADMIN_LEVEL)

	menu_setprop(menu, MPROP_EXIT, MEXIT_ALL)
  
	menuselection[id]=MENU_LEVEL

	menu_display(id, menu, 0)
	
	return PLUGIN_CONTINUE
}

public menu_handler(id,menu,item)
{
	if (item == MENU_EXIT)
	{
		menu_destroy(menu)
		return PLUGIN_HANDLED
	}

	new data[6], iName[64]
	new access, callback

	menu_item_getinfo(menu, item, access, data,5, iName, 63, callback)


	if (!(get_user_flags(id) & access) && access)
		return PLUGIN_HANDLED


	new key=str_to_num(data)

	switch (menuselection[id])
	{
		case MENU_BADGE:
		{
  			menuselected[id][0]=0
			menuselected[id][1]=key
			badgelevelmenu(id)
		}
		case MENU_LEVEL:
		{
			menuselected[id][2]=key

			playerlist(id)
		}
		case MENU_ADMIN:
		{
			switch (key)
			{
				case 0:	badgemenu(id)
				case 1:
				{
					menuselected[id][0]=1
					playerlist(id)
				}
				case 2: confirmmenuadmin(id)
			}
		}
		case MENU_MAIN:
		{
			switch (key)
			{
				case 0: helpmenu(id)
				case 1:	statsmenu(id)
				case 2:	adminmenu(id)
				case 3: confirmmenu(id)
			}
		}
		case MENU_STATS:
		{
			switch (key)
			{
				case 0: cmd_who(id)
				case 1:	
				{
					display_badges(id,id)
				}
				case 2:	show_stats(id)
				case 3: show_server_stats(id)
			}
		}
		case MENU_HELP:
		{
			switch (key)
			{
				case 0: cmd_help(id)
				case 1:	show_badgehelp(id)
				case 2:	show_badgehelp2(id)
				case 3: show_badgehelp3(id)
				case 4:	show_rankhelp(id)
			}
		}
		case MENU_CONFIRM:
		{
			switch (key)
			{
				case 0: reset_stats(id)
			}
		}
		case MENU_CONFIRMADMIN:
		{
			switch (key)
			{
				case 0: reset_all_stats(id)
			}
		}
		case MENU_PLAYER:
		{
			if (menuselected[id][0]==0) //User selected a badge
			{
				new name[30]
				get_user_name(key,name,29)
				new badge=menuselected[id][1]
				new level=menuselected[id][2]
				g_PlayerBadges[key][badge]=level
				client_print(id,print_chat,"[BF2]%s odznaka zostala przyznana dla gracza %s",BADGES[badge][level],name)
				save_badges(key)
				DisplayHUD(key)
				
				new adminauthid[35]
				new awardauthid[35]
				get_user_authid (id,adminauthid,34)
				get_user_authid (key,awardauthid,34)

				log_amx("[BF2-ADMIN]Admin %s przyznal odznake %s graczowi %s",adminauthid,BADGES[badge][level],awardauthid)
			}
			else //Kills
			{
				new name[30]
				get_user_name(key,name,29)
				new kills=menuselected[id][1]
				totalkills[key]+=kills
				client_print(id,print_chat,"[BF2]%d Fragi zostaly przyznane graczowi %s",kills,name)
				save_badges(key)
				DisplayHUD(key)
				
				new adminauthid[35]
				new awardauthid[35]
				get_user_authid (id,adminauthid,34)
				get_user_authid (key,awardauthid,34)

				log_amx("[BF2-ADMIN]Admin %s przyznal  %i fragow graczowi %s",adminauthid,kills,awardauthid)
			}
		}
	}

   	menu_destroy(menu)
    
	return PLUGIN_HANDLED
}
/* AMXX-Studio Notes - DO NOT MODIFY BELOW HERE
*{\\ rtf1\\ ansi\\ deff0{\\ fonttbl{\\ f0\\ fnil Tahoma;}}\n\\ viewkind4\\ uc1\\ pard\\ lang1045\\ f0\\ fs16 \n\\ par }
*/
